package com.mocha.thread;

import java.util.concurrent.*;



public class ThreadPoolTest {

    private static LinkedBlockingQueue queue = new LinkedBlockingQueue(10);

    private static ThreadFactory factory = Thread::new;

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 6, 30000L, TimeUnit.SECONDS, queue, factory);


    public ThreadPoolTest() {
    }

    public static void main(String[] args) {


//        checkStemps();

    }










    /**
     * 验证 线程池的加载
     *
     * corePoolSize
     *
     * maxPoolSize
     *
     * queue
     *
     */
    private static void checkStemps() {
        System.out.println();
        for (int i = 0; i < 20; i++) {
            System.out.println("i = "+i);
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(100000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            System.out.println("queue size = " + queue.size());
            System.out.println("active count now = " + executor.getActiveCount());
            System.out.println("=================================");
        }
    }

}
